/** modified  version
* @file			main.c
* @author  		Supachai Vorapojpisut
* @version 		1.0
* @date    		November 11, 2013
* @brief   		Template code for main program.
*/

/* Includes ------------------------------------------------------------------*/
#include "arduino.h"
#include "bluetooth_serial.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/**
* @brief	The setup() function will only run once, after each powerup or reset of the board. Use it to initialize variables, pin modes, start using libraries, etc.
* @param	None
* @retval	None
*/
void setup()
{
	Serial.begin(9600);
}


/**
* @brief	The loop() function does loop consecutively, allowing your program to change and respond. Use it to actively control the board.
* @param	None
* @retval	None
*/
void loop()
{
	
	
char room;
char onoff;
char action;
char buf[100];
	int i;
	
	if (Serial.available()) {
		// test case :- sending commands (e.g 1A1 0B1)  from smart phone and print them
		
		i = 0;
		do {
			buf[i++] = Serial.read();
		} while(Serial.available());
		buf[i] = 0;
		save_action(buf[0]); 
		save_room(buf[1]);
		save_onoff(buf[2]);
		
		
		//use get_action method and store current action 
		action = get_action(); 
		//use get_room method and store current room
		room= get_room();
		
		//use get_onoff method and store current onoff status
		onoff= get_onoff();
		
		
		// serial println all 
		Serial.println(&action); 
		Serial.println(&room); 
		Serial.println(&onoff);   
		
		
		
	} else {
		Serial.println(" no serial available ");
	}
	delay(1000);
}


/**
* @brief	Template main function
* @param	None
* @retval	None
*/
int main() 
{
	platform_config();
	setup();
	while(1) {
		loop();
	}
}
